<template>
  <div
    class="activity_wrap"
    v-loading="loading"
    element-loading-background="rgba(255, 255, 255, 0)"
  >
    <!-- <div class="introduce_wrap">
      <div class="editor_box">
        <ueEditor
          v-model="actDetails.introduction"
          @change="desChange"
          :temp="temp"
        ></ueEditor>
      </div>
      <div class="temp_box">
        <div class="temp_head">活动简介模板</div>
        <ul class="temp_list">
          <li
            class="temp_item"
            v-for="(item, index) in tempList"
            :key="index"
            @click="handleSelectTemp(item)"
            :class="{ active: tempId === item.id }"
          >
            <div v-html="item.data"></div>
          </li>
        </ul>
      </div>
    </div> -->
    <div class="introduce_wrap">
      <div class="editor_box">
        <ueEditor
          v-model="actDetails.introduction"
          @change="desChange"
          :temp="temp"
        ></ueEditor>
      </div>
      <!-- <div class="temp_wrap">
        <div class="title">活动简介模板</div>
        <ul class="temp_list">
          <li
            class="temp_item"
            v-for="(item, index) in tempList"
            :key="index"
            @click="handleSelectTemp(item)"
            :class="{ active: tempId === item.id }"
          >
            <div v-html="item.data"></div>
          </li>
        </ul>
      </div> -->
      <div class="temp_box">
        <div class="temp_head">活动简介模板</div>
        <ul class="temp_list">
          <li
            class="temp_item"
            v-for="(item, index) in tempList"
            :key="index"
            @click="handleSelectTemp(item)"
            :class="{ active: tempId === item.id }"
          >
            <div v-html="item.data"></div>
          </li>
        </ul>
      </div>
    </div>
    <div class="btn_wrap">
      <el-button @click="handleSave" type="primary">保存</el-button>
    </div>
  </div>
</template>

<script>
import ueEditor from "@/components/ueEditor";
import { mapGetters } from "vuex";
export default {
  components: { ueEditor },
  data() {
    return {
      actDetails: {},
      temp: "",
      tempList: [],
      tempId: "",
    };
  },
  computed: {
    ...mapGetters("status", {
      loading: "loading",
    }),
  },
  created() {
    this.getActDetail();
    this.$api("resource.getTemporary", {
      type: "INTRODUCTION",
    }).then((res) => {
      console.log(res);
      this.tempList = res;
    });
  },
  methods: {
    //获取活动信息
    getActDetail() {
      this.$api("vote.actById", {
        id: this.$route.query.id,
      }).then((res) => {
        this.actDetails = res;
        this.temp = this.actDetails.introduction;
      });
    },
    desChange(val) {
      this.actDetails.introduction = val;
    },
    //选择模板
    handleSelectTemp(item) {
      this.tempId = item.id;
      this.temp = item.data;
    },
    handleSave() {
      if (
        this.actDetails.introduction &&
        this.actDetails.introduction !== " "
      ) {
        this.$api("vote.save", this.actDetails).then((res) => {
          console.log(res);
          this.$store.commit("status/SET_URL", new Date().getTime());
          this.$message({
            message: "保存成功",
            type: "success",
            duration: 1000,
          });
        });
      } else {
        this.$message({
          message: "请填写活动介绍",
          type: "error",
          duration: 1000,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.activity_wrap {
  width: 924px;
  min-height: 550px;
  // .introduce_wrap {
  //   width: 800px;
  //   .temp_wrap {
  //     margin-top: 20px;
  //     .title{
  //       background: #f5f5f5;
  //       width: 120px;
  //       padding: 5px;
  //       border-radius: 0 28px 0 0;
  //       margin-bottom: 1px;
  //     }
  //     .temp_list {
  //       padding: 20px 30px;
  //       background: #f5f5f5;
  //       height: 360px;
  //       overflow-y: auto;
  //       display: flex;
  //       flex-wrap: wrap;
  //       justify-content: space-between;
  //       li {
  //         width: 300px;
  //       }
  //       .temp_item {
  //         font-size: 14px;
  //         height: 120px;
  //         overflow: hidden;
  //         background: #fff;
  //         user-select: none;
  //         box-shadow: 0 1px 7px 0 rgb(0 0 0 / 7%);
  //         border-radius: 4px;
  //         cursor: pointer;
  //         padding: 10px;
  //         margin: 15px 0;
  //         border: 1px solid transparent;

  //         > div {
  //           color: #666;
  //           text-align: justify;
  //           white-space: pre-wrap;
  //           line-height: 1.6;
  //           zoom: 0.67733;
  //         }
  //         &:hover {
  //           border-color: $themeColor;
  //         }
  //         &.active {
  //           border-color: $themeColor;
  //         }
  //       }
  //     }
  //   }
  // }
  .introduce_wrap {
    display: flex;
    height: 582px;
    .editor_box {
      flex: 1;
    }
    .temp_box {
      width: 283px;
      height: 100%;
      border: 1px solid #dcdfe6;
      background-color: #f5f6f8;
      box-sizing: border-box;

      .temp_head {
        width: 100%;
        height: 34px;
        line-height: 34px;
        text-align: center;
        border-bottom: 1px solid #dcdfe6;
      }
      .temp_list {
        overflow-y: auto;
        height: calc(100% - 34px);
        padding: 0 12px;
        .temp_item {
          font-size: 14px;
          width: 100%;
          height: 92px;
          overflow: hidden;
          background: #fff;
          user-select: none;
          box-shadow: 0 1px 7px 0 rgb(0 0 0 / 7%);
          border-radius: 4px;
          cursor: pointer;
          padding: 10px;
          margin: 15px 0;
          border: 1px solid transparent;

          > div {
            color: #666;
            text-align: justify;
            white-space: pre-wrap;
            line-height: 1.6;
            zoom: 0.67733;
          }
          &:hover {
            border-color: $themeColor;
          }
          &.active {
            border-color: $themeColor;
          }
        }
      }
    }
  }
  .btn_wrap {
    text-align: center;
    // margin-top: 20px;
    padding: 20px 0;
    ::v-deep.el-button {
      width: 150px;
    }
  }
}
</style>